package com.viroyal.monitorlib.entity;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;


/**
 * Created by wangshuofeng on 2017/6/17.
 */

public class AppInfo implements Comparable<AppInfo>, Parcelable {

    public int id;

    @SerializedName("name")
    public String name;

    @SerializedName("package")
    public String packageNmae;

    @SerializedName("apk_url")
    public String apk_url;

    @SerializedName("version_code")
    public int version_code;

    @SerializedName("page")
    public int page;

    @SerializedName("index")
    public int index;

    @SerializedName("need_auth")
    public int need_auth;

    @SerializedName("user_type")
    public int user_type;

    boolean isDownloading = false;
    // -1 未安装， 0 已安装，不用更新， 1 有更新
    int status = 0;
    //需要升级的app,下载到本地的地址
    String localUri = "";

    public boolean isDownloading() {
        return isDownloading;
    }

    public void setDownloading(boolean downloading) {
        isDownloading = downloading;
    }

    public AppInfo() {

    }

    public AppInfo(String name, String packageNmae, String apk_url, int version_code, int page, int index, int need_auth, int user_type) {
        this.name = name;
        this.packageNmae = packageNmae;
        this.apk_url = apk_url;
        this.version_code = version_code;
        this.page = page;
        this.index = index;
        this.need_auth = need_auth;
        this.user_type = user_type;
    }

    @Override
    public String toString() {
        return "AppInfo{" +
                ", name='" + name + '\'' +
                ", packageNmae='" + packageNmae + '\'' +
                ", apk_url='" + apk_url + '\'' +
                ", version_code=" + version_code +
                ", page=" + page +
                ", index=" + index +
                ", need_auth=" + need_auth +
                ", user_type=" + user_type +
                '}';
    }

    @Override
    public int compareTo(AppInfo appInfo) {
        int i = this.page - appInfo.page;
        if (i == 0) {
            return this.index = appInfo.index;
        }
        return i;
    }

    public AppInfo(Parcel source) {
        name = source.readString();
        packageNmae = source.readString();
        apk_url = source.readString();
        version_code = source.readInt();
        page = source.readInt();
        index = source.readInt();
        need_auth = source.readInt();
        user_type = source.readInt();
    }

    public static final Creator<AppInfo> CREATOR = new Creator<AppInfo>() {

        @Override
        public AppInfo createFromParcel(Parcel source) {
            return new AppInfo(source);
        }

        @Override
        public AppInfo[] newArray(int size) {
            return new AppInfo[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeString(packageNmae);
        dest.writeString(apk_url);
        dest.writeInt(version_code);
        dest.writeInt(page);
        dest.writeInt(index);
        dest.writeInt(need_auth);
        dest.writeInt(user_type);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPackageNmae() {
        return packageNmae;
    }

    public void setPackageNmae(String packageNmae) {
        this.packageNmae = packageNmae;
    }

    public String getApk_url() {
        return apk_url;
    }

    public void setApk_url(String apk_url) {
        this.apk_url = apk_url;
    }

    public int getVersion_code() {
        return version_code;
    }

    public void setVersion_code(int version_code) {
        this.version_code = version_code;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getNeed_auth() {
        return need_auth;
    }

    public void setNeed_auth(int need_auth) {
        this.need_auth = need_auth;
    }

    public int getUser_type() {
        return user_type;
    }

    public void setUser_type(int user_type) {
        this.user_type = user_type;
    }

    public int getStatus() {
        return status;
    }

    public String getStatusString() {
        if (status == 0) {
            return "";
        } else if (status == -1) {
            return " 未安装 " + getLocalUriRP();
        } else if (status == 1) {
            return " 新升级 " + getLocalUriRP();
        }
        return "";
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getLocalUri() {
        return localUri;
    }

    public void setLocalUri(String localUri) {
        this.localUri = localUri;
    }

    public String getLocalUriRP() {
        return "";
//        if (!TextUtils.isEmpty(localUri)) {
//            return "已下载";
//        } else {
//            return "未下载";
//        }
    }

}
